<template>
  <div class="home">
    <div class="banner">
      <!-- 轮播图 -->
      <!-- <Banner /> -->
      <SwiperBanner />
      <!-- 搜索框 -->
      <div class="search">
        <el-row :gutter="20">
          <el-col :span="8" :offset="8">
            <div class="input-bg">
              <el-input v-model="input" @focus="getInput" @blur="laveInput" placeholder="请输入内容"></el-input>
            </div>
            <!-- 显示下拉内容 -->
            <div class="list" v-show="isShow">
              <p class="info">温馨提示：可以直接输入城市的中文、英文来匹配检索</p>
              <div class="title">热门城市</div>
              <div class="hot-citys">
                <a href="##" v-for="item in hotcity" :key="item.id">{{ item.name }}</a>
              </div>
            </div>
            <!-- 显示搜索列表内容展示 -->
            <ul class="search-list" v-show="isShowList">
              <li v-for="item in searchList" :key="item.id">
                {{ item.name }} <span>{{ item.en_name }}</span>
              </li>
            </ul>

          </el-col>
        </el-row>
      </div>
    </div>
    <div v-if="isShow" class="mask"></div>
    <!-- 图片 -->
    <div class="section section-gray">
      <div class="wrapper">
        <ul>
          <li>
            <img src="@/assets/images/5.png" width="740px" alt="">
          </li>
          <li>
            <img src="@/assets/images/6.png" width="400px" alt="">
          </li>
        </ul>
      </div>
    </div>
    <!-- 今日推荐 -->
    <div class="section">
      <div class="wrapper">
        <div class="title-th">
          今日推荐
        </div>
        <div class="content">
          <el-row :gutter="20">
            <el-col :span="6" v-for="(item, index) in todyInfo" :key="index">
              <div class="item">
                <img :src="item.data.pic" alt="" width="275px" height="185px">
                <div class="info">
                  <div class="subtitle">{{ item.data.subject }}</div>
                  <div class="bottom">
                    <template v-if="item.type == 'video'">
                      <span class="fr">{{ item.data.tag }}</span>
                      <span class="f14">{{ item.data.desc }}</span>
                    </template>
                    <template v-else-if="item.type == 'bbs'">
                      <span class="fr">{{ item.data.views }}人浏览过</span>
                      <span class="f14">{{ item.data.username }}</span>
                    </template>
                    <template v-else>
                      <span class="fr money" v-html="item.data.price"></span>
                      <span class="f14">{{ item.data.start_pos }}</span>
                    </template>
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
        <!-- <div class="content">
            <el-row :gutter="20">
              <el-col :span="6" v-for="(item,index) in todyInfo" :key="index">
                <div class="item">
                  <img :src="item.pic" alt="">
                  <div class="info">
                    <div class="subtitle">{{item.data.subject}}</div>
                    <div class="bottom">
                      <span class="fr">7499人浏览过</span>
                      <span class="f14">smapvia</span>
                    </div>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div> -->
      </div>
    </div>
    <!-- 穷游商场 -->
    <HomeShop :shopList="shopList" @getMoreShop="getMoreShop" />
    <!-- 热门游记与话题 -->
    <HomeTravel />
    <div v-show="showAd" class="q-footer-ad" style="bottom: 90px;">
      <span class="ad-text">行程保障，保险先行，出游更安心！</span>
      <img src="@/assets/images/7.png" class="close" @click="hideAd">
    </div>
  </div>
</template>

<script>
// import Banner from './banner/Banner.vue';
import SwiperBanner from './banner/SwiperBanner.vue';
import HomeShop from './shop/HomeShop.vue';
import HomeTravel from './travel/HomeTravel.vue';

export default {
  name: 'HomeView',
  components: {
    // Banner,
    SwiperBanner,
    HomeShop,
    HomeTravel
  },
  data() {
    return {
      input: '',
      isShow: false,//是否显示热门城市
      isShowList: false,//是否显示搜索列表
      hotcity: [],//热门城市
      searchList: [],//搜索列表
      todyInfo: [],// 今日推荐
      shopList: [],// 商品列表
      page: 0,// 分页
      showAd: true
    }
  },
  //监听input
  watch: {
    input(val) {
      if (!val) {
        this.isShow = true;
        this.isShowList = false;
        return '';
      }
      this.isShow = false;
      this.isShowList = true;
      //网络请求
      this.$api.getSearchCity({
        keyword: val
      }).then(res => {
        console.log(res);
        this.searchList = res.data.list;
      })
    }
  },
  methods: {
    getInput() {
      if (this.input) {
        this.isShowList = true;
        return;
      }
      this.isShow = true;
    },

    laveInput() {
      this.isShow = false;
      this.isShowList = false;
    },
    async getHotCity() {
      let res = await this.$api.getHotCity();
      console.log("热门城市---", res);
      this.hotcity = res.result.hotcity;
    },
    hideAd() {
      this.showAd = false;
    },
    async getTodyInfo() {
      let res = await this.$api.getTodyInfo();
      console.log("今日推荐----", res);
      this.todyInfo = res.data;
    },
    // 获取商场推荐
    async getHomeShop(page) {
      let res = await this.$api.getHomeShop(page);
      console.log("商场推荐----", res);
      this.shopList = res.data;
    },
    getMoreShop() {
      this.page++;
      console.log("page", this.page);
      this.getHomeShop({
        page: this.page
      });
    },

  },
  beforeCreate() {
    // console.log ('父beforeCreate')
  },
  created() {
    // console.log ('父created')
    //获取当前城市
    this.getHotCity();
    //获取今日信息
    this.getTodyInfo();
    //获取商场推荐
    this.getHomeShop({
      page: this.page,
    });
  },
  beforeMount() {
    // console.log ('父beforeMount')
  },
  mounted() {
    //  console.log ('父mounted')
    setTimeout(() => {
      this.showAd = false;
    }, 25000); // 25秒后自动隐藏
  }
}
</script>

<style scoped>
.bg {
  background: rgba(255, 255, 255, .7);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding-top: 300px;
}

.banner {
  position: relative;

  .search {
    position: absolute;
    width: 100%;
    top: 50%;
    z-index: 99;

    .input-bg {
      background-image: linear-gradient(90deg, rgba(40, 213, 164, 8), rgba(38, 208, 181, 8));
      display: flex;
      align-items: center;
      padding: 10px;
      border-radius: 10px;
    }

    .search-list {
      /* 文字左对齐 */
      text-align: left;
    }
  }

  /* 热门城市 */
  .list {
    width: 100%;
    height: 280px;
    background-color: white;
    box-sizing: border-box;
    padding: 20px;
    border-radius: 5%;

    .info {
      font-size: 12px;
      color: #999;
    }

    .title {
      padding: 20px 0;
      border-bottom: 1px solid #eee;
    }

    .hot-citys {
      a {
        display: inline-block;
        margin: 20px 30px 10px 0;
        font-size: 14px;
        color: #666;
        text-decoration: none;
      }
    }
  }

  /* 搜索列表 */
  .search-list {
    width: 100%;
    min-height: 60px;
    background-color: white;
    padding-top: 10px;
    border-radius: 6px;
    margin-top: -5px;
    padding-bottom: 10px;

    li {
      padding: 10px;
    }
  }
}

.section {
  position: relative;
  padding: 10px 0;
  min-width: 1160px;
}

.wrapper {
  margin: 0 auto;
  width: 1160px;
}

.section.section-gray {
  border-color: #ececec;
  border-style: solid;
  border-width: 1px 0;
  background-color: #f5f5f5;

  ul {
    overflow: hidden;
    margin-right: -20px;
  }

  ul li {
    float: left;
    margin-right: 20px;
    height: 110px;
    border-radius: 3px;
    overflow: hidden;
    transition: all .2s ease-in-out;
  }
}

.title-th {
  margin: 10px;
  height: 74px;
  color: #636363;
  text-align: center;
  font: 36px / 74px Hiragino Sans GB, Microsoft YaHei, SimHei, SimSun, sans-serif;

  span {
    color: #c0c0c0;
    font-size: 18px;
  }
}

.content {
  .item {
    width: 275px;
    height: 300px;
    margin-bottom: 20px;
    overflow: hidden;

    img {
      width: 100%;
    }
  }

  .item:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    z-index: 1;
  }

  .item:hover img {
    transform: scale(1.05);
    filter: brightness(95%);
    transition: transform 0.5s ease;
  }

  .info {
    padding: 0 18px;
    border: 1px solid #ececec;
    border-top: 0;
    height: 114px;
    line-height: 24px;
    overflow: hidden;

    .subtitle {
      margin-top: 14px;
      height: 48px;
      font-size: 18px;
      overflow: hidden;
    }

    .bottom {
      margin-top: 16px;
      height: 24px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      color: #636363;
      text-align: left;
      font-size: 12px;
      font-weight: 700px;

      .fr {
        color: #959595;
        float: right;
      }

      .f14 {
        display: inline-block;
        max-width: 70%;
        min-width: 50%;
        color: #636363;
        font-size: 14px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
      }
    }
  }
}

::v-deep em {
  color: #f59388;
  font-size: 18px;
  font-style: normal;
}

.q-footer-ad {
  position: fixed;
  z-index: 9999;
  left: 20px;
  bottom: 20px;
  width: 300px;
  height: 50px;
  background: #40c067;
  border-radius: 5px;
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-align-items: center;
  align-items: center;

  .ad-text {
    flex: 1.5;
    color: #fff;
  }

  .close {
    width: 24px;
    height: 24px;
    position: absolute;
    right: 10px;
  }

  img {
    border: 0;
    overflow-clip-margin: content-box;
    overflow: clip;
  }
}

.q-footer-ad::after {
  content: "";
  display: block;
  position: absolute;
  width: 0;
  height: 0;
  border: 6px dashed transparent;
  border-top: 6px solid #40c067;
  bottom: -12px;
  left: 112px;
}
</style>